using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace LogParser.DA
{
    public class PlayerModel
    {

        private DA.DataObjects.PlayersDSTableAdapters.PlayersTableAdapter pta;
        private DA.DataObjects.PlayerStatsDSTableAdapters.PlayerStatsTeamTableAdapter pstta;
        private DA.DataObjects.PlayerStatsDSTableAdapters.PlayerStatsSelectByPlayerIdTableAdapter playerStatsSelectTA;
        private DA.DataObjects.PlayerStatsDSTableAdapters.PlayerShortStats playerShortStatsTA;

        private Collections.PointValueList _pointValueList;

        private const string SORT_KILLDEATHKILLDEATHRATIO = "Kills DESC, KillDeathRatio DESC, Deaths DESC";

        public PlayerModel()
        {
            pta = TableAdapters.PlayersTableAdapter();
            pstta = TableAdapters.PlayerStatsTeamTableAdapter();
            playerStatsSelectTA = TableAdapters.PlayerStatsSelectByPlayerIdTableAdapter();


            playerShortStatsTA = TableAdapters.PlayerShortStats();

            _pointValueList = new LogParser.Collections.PointValueList();
        }

        public static Player GetPlayer( string playerId )
        {
            Player returnPlayer = new Player();


            returnPlayer.PlayerId = playerId;

            DA.DataObjects.PlayerNameListDSTableAdapters.PlayerNameListTableAdapter pnlta = TableAdapters.PlayerNameListTableAdapter();
            DA.DataObjects.PlayerNameListDS.PlayerNameListDataTable dt = pnlta.PlayerNameListSelectById( playerId );

            foreach ( DA.DataObjects.PlayerNameListDS.PlayerNameListRow dr in dt.Rows )
            {
                returnPlayer.PlayerNames.Add( dr.PlayerName );
            }

            return returnPlayer;
        }

        public DA.DataObjects.PlayerStatsDS.PlayerStatsTeamRow GetPlayerTeamStatsRow( int logId, string playerId )
        {


            DA.DataObjects.PlayerStatsDS.PlayerStatsTeamDataTable psdt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerStatsTeamDataTable();
            psdt = pstta.GetData( logId, playerId );
            DA.DataObjects.PlayerStatsDS.PlayerStatsTeamRow returnRow = (DA.DataObjects.PlayerStatsDS.PlayerStatsTeamRow) psdt.Rows[ 0 ];

            returnRow.KillDeathRatio = CalculateKillDeathRatioFormatted( returnRow.Kills, returnRow.Deaths );

            CalculatePoints( ref returnRow );

            return returnRow;
        }

        public static DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow GetPlayerStatsRow( string playerId )
        {

            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerStatsSelectByPlayerIdTableAdapter tempPlayerStatsSelect = TableAdapters.PlayerStatsSelectByPlayerIdTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdDataTable pssdt = new DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdDataTable();
            pssdt = tempPlayerStatsSelect.GetData( playerId );
            DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow returnRow = (DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow) pssdt.Rows[ 0 ];

            returnRow.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( returnRow.Kills, returnRow.Deaths );

            pm.CalculatePoints( ref returnRow );

            return returnRow;
        }


        public static DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow GetPlayerStatsRow( string playerId, string logId )
        {

            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerStatsSelectByPlayerIdTableAdapter tempPlayerStatsSelect = TableAdapters.PlayerStatsSelectByPlayerIdTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdDataTable pssdt = new DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdDataTable();
            pssdt = tempPlayerStatsSelect.PlayerStatsSelectByPlayerIdLogId( playerId, logId );
            DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow returnRow = (DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow) pssdt.Rows[ 0 ];

            returnRow.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( returnRow.Kills, returnRow.Deaths );

            pm.CalculatePoints( ref returnRow );

            return returnRow;
        }

        public static DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable GetPlayerClassStats( string playerId )
        {

            LogParser.Collections.ClassList classList = new LogParser.Collections.ClassList();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerClassStatsTableAdapter classStatsTA = TableAdapters.PlayerClassStatsTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable returnClass = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable();

            PlayerModel pm = new PlayerModel();


            foreach ( GameObjects.Class tempClass in classList.GetClassList.Values )
            {
                DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable pcsdt = classStatsTA.GetData( playerId, tempClass.ID );

                DA.DataObjects.PlayerStatsDS.PlayerClassStatsRow dr = returnClass.NewPlayerClassStatsRow();

                dr.ItemArray = ( (DA.DataObjects.PlayerStatsDS.PlayerClassStatsRow) pcsdt.Rows[ 0 ] ).ItemArray;
                dr.TimesPlayed = ( (DA.DataObjects.PlayerStatsDS.PlayerClassStatsRow) pcsdt.Rows[ 0 ] ).TimesPlayed;
                dr.ClassId = tempClass.ID;
                dr.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( dr.Kills, dr.Deaths );
                dr.Points = 0;

                returnClass.Rows.Add( dr );
            }

            DataView dv = new DataView( returnClass );
            dv.Sort = "Points DESC, " + SORT_KILLDEATHKILLDEATHRATIO;
            DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable returnTable2 = (DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable) returnClass.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable2.ImportRow( dvr.Row );

            returnClass.Clear();

            return returnTable2;
        }


        public static DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable GetPlayerClassStats( string playerId, string logIdList )
        {

            LogParser.Collections.ClassList classList = new LogParser.Collections.ClassList();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerClassStatsTableAdapter classStatsTA = TableAdapters.PlayerClassStatsTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable returnClass = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable();

            PlayerModel pm = new PlayerModel();


            foreach ( GameObjects.Class tempClass in classList.GetClassList.Values )
            {
                DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable pcsdt = classStatsTA.PlayerClassStatsSelectByPlayerIdLogId( playerId, tempClass.ID, logIdList );

                DA.DataObjects.PlayerStatsDS.PlayerClassStatsRow dr = returnClass.NewPlayerClassStatsRow();

                dr.ItemArray = ( (DA.DataObjects.PlayerStatsDS.PlayerClassStatsRow) pcsdt.Rows[ 0 ] ).ItemArray;
                dr.TimesPlayed = ( (DA.DataObjects.PlayerStatsDS.PlayerClassStatsRow) pcsdt.Rows[ 0 ] ).TimesPlayed;
                dr.ClassId = tempClass.ID;
                dr.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( dr.Kills, dr.Deaths );
                dr.Points = 0;

                returnClass.Rows.Add( dr );
            }

            DataView dv = new DataView( returnClass );
            dv.Sort = "Points DESC, " + SORT_KILLDEATHKILLDEATHRATIO;
            DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable returnTable2 = (DA.DataObjects.PlayerStatsDS.PlayerClassStatsDataTable) returnClass.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable2.ImportRow( dvr.Row );

            returnClass.Clear();

            return returnTable2;
        }


        public static DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable GetPlayerShortStats()
        {
            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerShortStats tempPlayerShortStatsTA = TableAdapters.PlayerShortStats();
            DA.DataObjects.PlayersDSTableAdapters.PlayersTableAdapter tempPlayersTA = TableAdapters.PlayersTableAdapter();
            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerStatsSelectByPlayerIdTableAdapter tempPlayerStatsSelect = TableAdapters.PlayerStatsSelectByPlayerIdTableAdapter();

            DA.DataObjects.PlayersDS.PlayersDataTable pdt = tempPlayersTA.PlayersSelectList();
            DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable returnTable = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable();

            PlayerModel pm = new PlayerModel();


            foreach ( DA.DataObjects.PlayersDS.PlayersRow dr in pdt.Rows )
            {
                DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable pssdt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable();
                pssdt = tempPlayerShortStatsTA.GetData( dr.PlayerId );

                DA.DataObjects.PlayerStatsDS.PlayerShortStatsRow drShort = returnTable.NewPlayerShortStatsRow();

                drShort.ItemArray = ( (DA.DataObjects.PlayerStatsDS.PlayerShortStatsRow) pssdt.Rows[ 0 ] ).ItemArray;

                drShort.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( drShort.Kills, drShort.Deaths );


                DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow playerStatsSelectRow = ( (DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow) tempPlayerStatsSelect.GetData( dr.PlayerId ).Rows[ 0 ] );


                pm.CalculatePoints( ref playerStatsSelectRow );
                drShort.Points = playerStatsSelectRow.Points;

                returnTable.Rows.Add( drShort );

            }



            DataView dv = new DataView( returnTable );
            dv.Sort = "Points DESC, " + SORT_KILLDEATHKILLDEATHRATIO;
            DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable returnTable2 = (DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable) returnTable.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable2.ImportRow( dvr.Row );

            returnTable.Clear();

            return returnTable2;
        }

        public static DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable GetPlayerShortStatsByLogId( string logIdList )
        {
            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerShortStats tempPlayerShortStatsTA = TableAdapters.PlayerShortStats();
            DA.DataObjects.PlayersDSTableAdapters.PlayersTableAdapter tempPlayersTA = TableAdapters.PlayersTableAdapter();
            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerStatsSelectByPlayerIdTableAdapter tempPlayerStatsSelect = TableAdapters.PlayerStatsSelectByPlayerIdTableAdapter();

            DA.DataObjects.PlayersDS.PlayersDataTable pdt = tempPlayersTA.PlayersSelectList();
            DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable returnTable = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable();

            PlayerModel pm = new PlayerModel();


            foreach ( DA.DataObjects.PlayersDS.PlayersRow dr in pdt.Rows )
            {
                DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable pssdt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable();
                pssdt = tempPlayerShortStatsTA.PlayerShortStatsSelectByPlayerIdLogId( dr.PlayerId, logIdList );

                DA.DataObjects.PlayerStatsDS.PlayerShortStatsRow drShort = returnTable.NewPlayerShortStatsRow();

                drShort.ItemArray = ( (DA.DataObjects.PlayerStatsDS.PlayerShortStatsRow) pssdt.Rows[ 0 ] ).ItemArray;

                drShort.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( drShort.Kills, drShort.Deaths );


                DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow playerStatsSelectRow = ( (DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow) tempPlayerStatsSelect.PlayerStatsSelectByPlayerIdLogId( dr.PlayerId, logIdList ).Rows[ 0 ] );


                pm.CalculatePoints( ref playerStatsSelectRow );
                drShort.Points = playerStatsSelectRow.Points;

                if (drShort.Kills >0 || drShort.Deaths > 0 || drShort.Points > 0)
                    returnTable.Rows.Add( drShort );

            }



            DataView dv = new DataView( returnTable );
            dv.Sort = "Points DESC, " + SORT_KILLDEATHKILLDEATHRATIO;
            DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable returnTable2 = (DA.DataObjects.PlayerStatsDS.PlayerShortStatsDataTable) returnTable.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable2.ImportRow( dvr.Row );

            returnTable.Clear();

            return returnTable2;
        }


        // GetVictims
        public static DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable GetPlayerVictims( string playerId )
        {
            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerVictimsSelectByPlayerIdTableAdapter pvta = TableAdapters.PlayerVictimsSelectByPlayerIdTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable pvdt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable();

            pvdt = pvta.GetData( playerId );

            foreach ( DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdRow dr in pvdt.Rows )
            {
                dr.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( dr.Kills, dr.Deaths );
            }

            DataView dv = new DataView( pvdt );
            dv.Sort = SORT_KILLDEATHKILLDEATHRATIO;

            DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable returnTable = (DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable) pvdt.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable.ImportRow( dvr.Row );

            pvdt.Clear();

            return returnTable;

        }

        // GetVictims
        public static DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable GetPlayerVictims( string playerId, string logIdList )
        {
            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerVictimsSelectByPlayerIdTableAdapter pvta = TableAdapters.PlayerVictimsSelectByPlayerIdTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable pvdt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable();

            pvdt = pvta.PlayerVictimsSelectByPlayerIdLogId( playerId, logIdList );

            foreach ( DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdRow dr in pvdt.Rows )
            {
                dr.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( dr.Kills, dr.Deaths );
            }

            DataView dv = new DataView( pvdt );
            dv.Sort = SORT_KILLDEATHKILLDEATHRATIO;

            DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable returnTable = (DA.DataObjects.PlayerStatsDS.PlayerVictimsSelectByPlayerIdDataTable) pvdt.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable.ImportRow( dvr.Row );

            pvdt.Clear();

            return returnTable;

        }

        // Get Top 5 Deaths
        public static DA.DataObjects.PlayerStatsDS.PlayersSelectTop5DeathsDataTable GetPlayerTop5Deaths()
        {
            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayersSelectTop5DeathsTableAdapter ta = TableAdapters.PlayersSelectTop5DeathsTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayersSelectTop5DeathsDataTable deathsDT = new LogParser.DA.DataObjects.PlayerStatsDS.PlayersSelectTop5DeathsDataTable();

            deathsDT = ta.GetData();

            return deathsDT;

        }

        // Get Top 5 Deaths
        public static DA.DataObjects.PlayerStatsDS.PlayersSelectPlayerKillersTop5ByVictimPlayerIdDataTable GetTop5PlayerKillers( string victimPlayerId )
        {
            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayersSelectPlayerKillersTop5ByVictimPlayerIdTableAdapter ta = TableAdapters.PlayersSelectPlayerKillersTop5ByVictimPlayerIdTableAdapter();
            DA.DataObjects.PlayerStatsDS.PlayersSelectPlayerKillersTop5ByVictimPlayerIdDataTable dt = ta.GetData( victimPlayerId );

            return dt;

        }

        public static DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable GetPlayerWeaponStats( string playerId )
        {
            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerWeaponStatsSelectByPlayerIdTableAdapter playerWeaponStatsTA = TableAdapters.PlayerWeaponStatsSelectByPlayerIdTableAdapter();

            Collections.WeaponList weaponListObject = new LogParser.Collections.WeaponList();
            Hashtable weaponList = weaponListObject.GetWeaponList();

            DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable pwsdt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable();


            foreach ( GameObjects.Weapon weapon in weaponList.Values )
            {
                DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdRow dr = pwsdt.NewPlayerWeaponStatsSelectByPlayerIdRow();
                DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable dt2 = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable();

                dt2 = playerWeaponStatsTA.GetData( playerId, weapon.WeaponID );

                if ( Convert.ToInt32( dt2.Rows[ 0 ][ "Kills" ] ) > 0 || Convert.ToInt32( dt2.Rows[ 0 ][ "Deaths" ] ) > 0 )
                {
                    dr.ItemArray = ( (DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdRow) dt2.Rows[ 0 ] ).ItemArray;
                    dr.WeaponId = weapon.WeaponID;
                    dr.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( dr.Kills, dr.Deaths );

                    pwsdt.Rows.Add( dr );
                }
            }



            //System.Data.DataRow[] tempRows = pwsdt.Select( "", "Kills DESC, KillDeathRatio DESC, Deaths DESC" );

            DataView dv = new DataView( pwsdt );

            dv.Sort = SORT_KILLDEATHKILLDEATHRATIO;

            DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable returnTable = (DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable) pwsdt.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable.ImportRow( dvr.Row );

            pwsdt.Clear();

            //returnTable.Rows.Add(  );

            return returnTable;

        }

        public static DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable GetPlayerWeaponStats( string playerId, string logIdList )
        {
            PlayerModel pm = new PlayerModel();

            DA.DataObjects.PlayerStatsDSTableAdapters.PlayerWeaponStatsSelectByPlayerIdTableAdapter playerWeaponStatsTA = TableAdapters.PlayerWeaponStatsSelectByPlayerIdTableAdapter();

            Collections.WeaponList weaponListObject = new LogParser.Collections.WeaponList();
            Hashtable weaponList = weaponListObject.GetWeaponList();

            DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable pwsdt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable();


            foreach ( GameObjects.Weapon weapon in weaponList.Values )
            {
                DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdRow dr = pwsdt.NewPlayerWeaponStatsSelectByPlayerIdRow();
                DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable dt2 = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable();

                dt2 = playerWeaponStatsTA.PlayerWeaponStatsSelectByPlayerIdLogIdList( playerId, weapon.WeaponID.ToString(), logIdList );  // here

                if ( Convert.ToInt32( dt2.Rows[ 0 ][ "Kills" ] ) > 0 || Convert.ToInt32( dt2.Rows[ 0 ][ "Deaths" ] ) > 0 )
                {
                    dr.ItemArray = ( (DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdRow) dt2.Rows[ 0 ] ).ItemArray;
                    dr.WeaponId = weapon.WeaponID;
                    dr.KillDeathRatio = pm.CalculateKillDeathRatioFormatted( dr.Kills, dr.Deaths );

                    pwsdt.Rows.Add( dr );
                }
            }



            //System.Data.DataRow[] tempRows = pwsdt.Select( "", "Kills DESC, KillDeathRatio DESC, Deaths DESC" );

            DataView dv = new DataView( pwsdt );

            dv.Sort = SORT_KILLDEATHKILLDEATHRATIO;

            DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable returnTable = (DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable) pwsdt.Clone();

            foreach ( DataRowView dvr in dv )
                returnTable.ImportRow( dvr.Row );

            pwsdt.Clear();

            //returnTable.Rows.Add(  );

            return returnTable;

        }


        private string CalculateKillDeathRatioFormatted( int kills, int deaths )
        {

            return CalculateKillDeathRatioFormatted( Convert.ToDouble( kills ), Convert.ToDouble( deaths ) );
        }

        private string CalculateKillDeathRatioFormatted( double kills, double deaths )
        {

            if ( deaths == 0 )
                deaths = 1;

            double totalRatio = kills / deaths;
            return string.Format( "{0:0.00}", totalRatio );
        }

        #region CalculatePoints

        private void CalculatePoints( ref DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow dr )
        {
            double points = 0;

            points += _pointValueList.GetKillAssistPoints( dr.Assists );
            points += _pointValueList.GetKillPoints( dr.Kills );
            points += _pointValueList.GetCapturePoints( dr.Captures );
            points += _pointValueList.GetCapturePoints( dr.FlagsCaptured );
            points += _pointValueList.GetDefensePoints( dr.CaptureBlocks );
            points += _pointValueList.GetDefensePoints( dr.FlagsDefended );
            points += _pointValueList.GetDestructionPoints( dr.Destructions );
            points += _pointValueList.GetRevengePoints( dr.Revenges );
            points += _pointValueList.GetBuiltObjectPoints( dr.BuiltObjects );
            //points += ( (double) dr.Assists ) * _pointValueList.GetPointValue( "healing" );  // not used currently
            points += _pointValueList.GetChargeDeployedPoints( dr.Ubers );

            points += _pointValueList.GetHeadshotPoints( dr.Headshots );  // headshots
            points += _pointValueList.GetBackstabPoints( dr.Backstabs );  // backstabs

            dr.Points = points;

        }

        private void CalculatePoints( ref DA.DataObjects.PlayerStatsDS.PlayerStatsTeamRow dr )
        {
            double points = 0;

            points += _pointValueList.GetKillAssistPoints( dr.Assists );
            points += _pointValueList.GetKillPoints( dr.Kills );
            points += _pointValueList.GetCapturePoints( dr.Captures );
            points += _pointValueList.GetDefensePoints( dr.CaptureBlocks );
            points += _pointValueList.GetDefensePoints( dr.FlagsDefended );
            points += _pointValueList.GetDestructionPoints( dr.Destructions );
            points += _pointValueList.GetRevengePoints( dr.Revenges );
            points += _pointValueList.GetBuiltObjectPoints( dr.BuiltObjects );
            //points += ( (double) dr.Assists ) * _pointValueList.GetPointValue( "healing" );  // not used currently
            points += _pointValueList.GetChargeDeployedPoints( dr.Ubers );

            points += _pointValueList.GetHeadshotPoints( dr.Headshots );  // headshots
            points += _pointValueList.GetBackstabPoints( dr.Backstabs );  // backstabs

            dr.Points = points;
            //dr.Points = String.Format( "{0:0.00}", Convert.ToString( points ) );

        }


        #endregion

    }
}
